// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Aggregations;

public sealed partial class CompositeAggregationSource
{
	/// <summary>
	/// <para>
	/// A date histogram aggregation.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("date_histogram")]
	public Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeDateHistogramAggregation? DateHistogram { get; set; }

	/// <summary>
	/// <para>
	/// A geotile grid aggregation.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("geotile_grid")]
	public Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeGeoTileGridAggregation? GeotileGrid { get; set; }

	/// <summary>
	/// <para>
	/// A histogram aggregation.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("histogram")]
	public Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeHistogramAggregation? Histogram { get; set; }

	/// <summary>
	/// <para>
	/// A terms aggregation.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("terms")]
	public Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeTermsAggregation? Terms { get; set; }
}

public sealed partial class CompositeAggregationSourceDescriptor<TDocument> : SerializableDescriptor<CompositeAggregationSourceDescriptor<TDocument>>
{
	internal CompositeAggregationSourceDescriptor(Action<CompositeAggregationSourceDescriptor<TDocument>> configure) => configure.Invoke(this);

	public CompositeAggregationSourceDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeDateHistogramAggregation? DateHistogramValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeDateHistogramAggregationDescriptor<TDocument> DateHistogramDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeDateHistogramAggregationDescriptor<TDocument>> DateHistogramDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeGeoTileGridAggregation? GeotileGridValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeGeoTileGridAggregationDescriptor<TDocument> GeotileGridDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeGeoTileGridAggregationDescriptor<TDocument>> GeotileGridDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeHistogramAggregation? HistogramValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeHistogramAggregationDescriptor<TDocument> HistogramDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeHistogramAggregationDescriptor<TDocument>> HistogramDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeTermsAggregation? TermsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeTermsAggregationDescriptor<TDocument> TermsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeTermsAggregationDescriptor<TDocument>> TermsDescriptorAction { get; set; }

	/// <summary>
	/// <para>
	/// A date histogram aggregation.
	/// </para>
	/// </summary>
	public CompositeAggregationSourceDescriptor<TDocument> DateHistogram(Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeDateHistogramAggregation? dateHistogram)
	{
		DateHistogramDescriptor = null;
		DateHistogramDescriptorAction = null;
		DateHistogramValue = dateHistogram;
		return Self;
	}

	public CompositeAggregationSourceDescriptor<TDocument> DateHistogram(Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeDateHistogramAggregationDescriptor<TDocument> descriptor)
	{
		DateHistogramValue = null;
		DateHistogramDescriptorAction = null;
		DateHistogramDescriptor = descriptor;
		return Self;
	}

	public CompositeAggregationSourceDescriptor<TDocument> DateHistogram(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeDateHistogramAggregationDescriptor<TDocument>> configure)
	{
		DateHistogramValue = null;
		DateHistogramDescriptor = null;
		DateHistogramDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// A geotile grid aggregation.
	/// </para>
	/// </summary>
	public CompositeAggregationSourceDescriptor<TDocument> GeotileGrid(Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeGeoTileGridAggregation? geotileGrid)
	{
		GeotileGridDescriptor = null;
		GeotileGridDescriptorAction = null;
		GeotileGridValue = geotileGrid;
		return Self;
	}

	public CompositeAggregationSourceDescriptor<TDocument> GeotileGrid(Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeGeoTileGridAggregationDescriptor<TDocument> descriptor)
	{
		GeotileGridValue = null;
		GeotileGridDescriptorAction = null;
		GeotileGridDescriptor = descriptor;
		return Self;
	}

	public CompositeAggregationSourceDescriptor<TDocument> GeotileGrid(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeGeoTileGridAggregationDescriptor<TDocument>> configure)
	{
		GeotileGridValue = null;
		GeotileGridDescriptor = null;
		GeotileGridDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// A histogram aggregation.
	/// </para>
	/// </summary>
	public CompositeAggregationSourceDescriptor<TDocument> Histogram(Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeHistogramAggregation? histogram)
	{
		HistogramDescriptor = null;
		HistogramDescriptorAction = null;
		HistogramValue = histogram;
		return Self;
	}

	public CompositeAggregationSourceDescriptor<TDocument> Histogram(Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeHistogramAggregationDescriptor<TDocument> descriptor)
	{
		HistogramValue = null;
		HistogramDescriptorAction = null;
		HistogramDescriptor = descriptor;
		return Self;
	}

	public CompositeAggregationSourceDescriptor<TDocument> Histogram(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeHistogramAggregationDescriptor<TDocument>> configure)
	{
		HistogramValue = null;
		HistogramDescriptor = null;
		HistogramDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// A terms aggregation.
	/// </para>
	/// </summary>
	public CompositeAggregationSourceDescriptor<TDocument> Terms(Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeTermsAggregation? terms)
	{
		TermsDescriptor = null;
		TermsDescriptorAction = null;
		TermsValue = terms;
		return Self;
	}

	public CompositeAggregationSourceDescriptor<TDocument> Terms(Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeTermsAggregationDescriptor<TDocument> descriptor)
	{
		TermsValue = null;
		TermsDescriptorAction = null;
		TermsDescriptor = descriptor;
		return Self;
	}

	public CompositeAggregationSourceDescriptor<TDocument> Terms(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeTermsAggregationDescriptor<TDocument>> configure)
	{
		TermsValue = null;
		TermsDescriptor = null;
		TermsDescriptorAction = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (DateHistogramDescriptor is not null)
		{
			writer.WritePropertyName("date_histogram");
			JsonSerializer.Serialize(writer, DateHistogramDescriptor, options);
		}
		else if (DateHistogramDescriptorAction is not null)
		{
			writer.WritePropertyName("date_histogram");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeDateHistogramAggregationDescriptor<TDocument>(DateHistogramDescriptorAction), options);
		}
		else if (DateHistogramValue is not null)
		{
			writer.WritePropertyName("date_histogram");
			JsonSerializer.Serialize(writer, DateHistogramValue, options);
		}

		if (GeotileGridDescriptor is not null)
		{
			writer.WritePropertyName("geotile_grid");
			JsonSerializer.Serialize(writer, GeotileGridDescriptor, options);
		}
		else if (GeotileGridDescriptorAction is not null)
		{
			writer.WritePropertyName("geotile_grid");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeGeoTileGridAggregationDescriptor<TDocument>(GeotileGridDescriptorAction), options);
		}
		else if (GeotileGridValue is not null)
		{
			writer.WritePropertyName("geotile_grid");
			JsonSerializer.Serialize(writer, GeotileGridValue, options);
		}

		if (HistogramDescriptor is not null)
		{
			writer.WritePropertyName("histogram");
			JsonSerializer.Serialize(writer, HistogramDescriptor, options);
		}
		else if (HistogramDescriptorAction is not null)
		{
			writer.WritePropertyName("histogram");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeHistogramAggregationDescriptor<TDocument>(HistogramDescriptorAction), options);
		}
		else if (HistogramValue is not null)
		{
			writer.WritePropertyName("histogram");
			JsonSerializer.Serialize(writer, HistogramValue, options);
		}

		if (TermsDescriptor is not null)
		{
			writer.WritePropertyName("terms");
			JsonSerializer.Serialize(writer, TermsDescriptor, options);
		}
		else if (TermsDescriptorAction is not null)
		{
			writer.WritePropertyName("terms");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeTermsAggregationDescriptor<TDocument>(TermsDescriptorAction), options);
		}
		else if (TermsValue is not null)
		{
			writer.WritePropertyName("terms");
			JsonSerializer.Serialize(writer, TermsValue, options);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class CompositeAggregationSourceDescriptor : SerializableDescriptor<CompositeAggregationSourceDescriptor>
{
	internal CompositeAggregationSourceDescriptor(Action<CompositeAggregationSourceDescriptor> configure) => configure.Invoke(this);

	public CompositeAggregationSourceDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeDateHistogramAggregation? DateHistogramValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeDateHistogramAggregationDescriptor DateHistogramDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeDateHistogramAggregationDescriptor> DateHistogramDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeGeoTileGridAggregation? GeotileGridValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeGeoTileGridAggregationDescriptor GeotileGridDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeGeoTileGridAggregationDescriptor> GeotileGridDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeHistogramAggregation? HistogramValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeHistogramAggregationDescriptor HistogramDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeHistogramAggregationDescriptor> HistogramDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeTermsAggregation? TermsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeTermsAggregationDescriptor TermsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeTermsAggregationDescriptor> TermsDescriptorAction { get; set; }

	/// <summary>
	/// <para>
	/// A date histogram aggregation.
	/// </para>
	/// </summary>
	public CompositeAggregationSourceDescriptor DateHistogram(Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeDateHistogramAggregation? dateHistogram)
	{
		DateHistogramDescriptor = null;
		DateHistogramDescriptorAction = null;
		DateHistogramValue = dateHistogram;
		return Self;
	}

	public CompositeAggregationSourceDescriptor DateHistogram(Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeDateHistogramAggregationDescriptor descriptor)
	{
		DateHistogramValue = null;
		DateHistogramDescriptorAction = null;
		DateHistogramDescriptor = descriptor;
		return Self;
	}

	public CompositeAggregationSourceDescriptor DateHistogram(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeDateHistogramAggregationDescriptor> configure)
	{
		DateHistogramValue = null;
		DateHistogramDescriptor = null;
		DateHistogramDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// A geotile grid aggregation.
	/// </para>
	/// </summary>
	public CompositeAggregationSourceDescriptor GeotileGrid(Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeGeoTileGridAggregation? geotileGrid)
	{
		GeotileGridDescriptor = null;
		GeotileGridDescriptorAction = null;
		GeotileGridValue = geotileGrid;
		return Self;
	}

	public CompositeAggregationSourceDescriptor GeotileGrid(Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeGeoTileGridAggregationDescriptor descriptor)
	{
		GeotileGridValue = null;
		GeotileGridDescriptorAction = null;
		GeotileGridDescriptor = descriptor;
		return Self;
	}

	public CompositeAggregationSourceDescriptor GeotileGrid(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeGeoTileGridAggregationDescriptor> configure)
	{
		GeotileGridValue = null;
		GeotileGridDescriptor = null;
		GeotileGridDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// A histogram aggregation.
	/// </para>
	/// </summary>
	public CompositeAggregationSourceDescriptor Histogram(Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeHistogramAggregation? histogram)
	{
		HistogramDescriptor = null;
		HistogramDescriptorAction = null;
		HistogramValue = histogram;
		return Self;
	}

	public CompositeAggregationSourceDescriptor Histogram(Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeHistogramAggregationDescriptor descriptor)
	{
		HistogramValue = null;
		HistogramDescriptorAction = null;
		HistogramDescriptor = descriptor;
		return Self;
	}

	public CompositeAggregationSourceDescriptor Histogram(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeHistogramAggregationDescriptor> configure)
	{
		HistogramValue = null;
		HistogramDescriptor = null;
		HistogramDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// A terms aggregation.
	/// </para>
	/// </summary>
	public CompositeAggregationSourceDescriptor Terms(Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeTermsAggregation? terms)
	{
		TermsDescriptor = null;
		TermsDescriptorAction = null;
		TermsValue = terms;
		return Self;
	}

	public CompositeAggregationSourceDescriptor Terms(Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeTermsAggregationDescriptor descriptor)
	{
		TermsValue = null;
		TermsDescriptorAction = null;
		TermsDescriptor = descriptor;
		return Self;
	}

	public CompositeAggregationSourceDescriptor Terms(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeTermsAggregationDescriptor> configure)
	{
		TermsValue = null;
		TermsDescriptor = null;
		TermsDescriptorAction = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (DateHistogramDescriptor is not null)
		{
			writer.WritePropertyName("date_histogram");
			JsonSerializer.Serialize(writer, DateHistogramDescriptor, options);
		}
		else if (DateHistogramDescriptorAction is not null)
		{
			writer.WritePropertyName("date_histogram");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeDateHistogramAggregationDescriptor(DateHistogramDescriptorAction), options);
		}
		else if (DateHistogramValue is not null)
		{
			writer.WritePropertyName("date_histogram");
			JsonSerializer.Serialize(writer, DateHistogramValue, options);
		}

		if (GeotileGridDescriptor is not null)
		{
			writer.WritePropertyName("geotile_grid");
			JsonSerializer.Serialize(writer, GeotileGridDescriptor, options);
		}
		else if (GeotileGridDescriptorAction is not null)
		{
			writer.WritePropertyName("geotile_grid");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeGeoTileGridAggregationDescriptor(GeotileGridDescriptorAction), options);
		}
		else if (GeotileGridValue is not null)
		{
			writer.WritePropertyName("geotile_grid");
			JsonSerializer.Serialize(writer, GeotileGridValue, options);
		}

		if (HistogramDescriptor is not null)
		{
			writer.WritePropertyName("histogram");
			JsonSerializer.Serialize(writer, HistogramDescriptor, options);
		}
		else if (HistogramDescriptorAction is not null)
		{
			writer.WritePropertyName("histogram");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeHistogramAggregationDescriptor(HistogramDescriptorAction), options);
		}
		else if (HistogramValue is not null)
		{
			writer.WritePropertyName("histogram");
			JsonSerializer.Serialize(writer, HistogramValue, options);
		}

		if (TermsDescriptor is not null)
		{
			writer.WritePropertyName("terms");
			JsonSerializer.Serialize(writer, TermsDescriptor, options);
		}
		else if (TermsDescriptorAction is not null)
		{
			writer.WritePropertyName("terms");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.CompositeTermsAggregationDescriptor(TermsDescriptorAction), options);
		}
		else if (TermsValue is not null)
		{
			writer.WritePropertyName("terms");
			JsonSerializer.Serialize(writer, TermsValue, options);
		}

		writer.WriteEndObject();
	}
}